typedef struct {
    int state;
} Memento;

typedef struct {
    int state;
    Memento* (*create_memento)(void);
    void (*restore_from_memento)(Memento*);
} Originator;

Memento* create_memento(Originator *originator){
    Memento *memento = (Memento *)malloc(sizeof(Memento));
    memento->state = originator->state;
    return memento;
}

void restore_from_memento(Originator *originator, Memento *memento){
    if(memento != NULL){
        originator->state = memento->state;
        free(memento); // 清理内存
    }
}
